Why does my Java print method return an object reference instead of the expected value